home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Fish Fillets / script / cabin1 / code.lua next >
Text File  |  2005-07-16  |  15KB  |  384 lines

  1.  
  2. -- -----------------------------------------------------------------
  3. -- Init
  4. -- -----------------------------------------------------------------
  5. local function prog_init()
  6.     initModels()
  7.     sound_playMusic("music/rybky04.ogg")
  8.     local pokus = getRestartCount()
  9.  
  10.  
  11.     -- -------------------------------------------------------------
  12.     local function prog_init_room()
  13.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  14.  
  15.         room.podekovat = 0
  16.         if random(100) < 50 then
  17.             room.atmosf = random(200) + 100
  18.             room.podiv = -1
  19.         else
  20.             room.podiv = 20
  21.             room.atmosf = -1
  22.         end
  23.         room.chob = random(2) + 1
  24.         room.truh = random(40) + 10
  25.         room.mov = 0
  26.         room.nekro = 0
  27.         local screenShiftX, screenShiftY = 0, 0
  28.         --NOTE: turn off standard black jokes
  29.         stdBlackJoke = function() end
  30.  
  31.         return function()
  32.             if not small:isAlive() or not big:isAlive() then
  33.                 if room.nekro == 0 then
  34.                     planDialogSet(6, "k1-pap-karamba", 101, papouch, "stav")
  35.                 end
  36.                 room.nekro = 1
  37.             else
  38.                 if chobot.dir ~= dir_no then
  39.                     room.podekovat = 1
  40.                 end
  41.                 if room.atmosf >= 0 then
  42.                     if room.atmosf == 0 then
  43.                         if no_dialog() then
  44.                             addv(50, "k1-v-citis")
  45.                             addm(1, "k1-m-kolebku")
  46.                             addv(2, "k1-v-cit")
  47.                         else
  48.                             room.atmosf = room.atmosf + 20
  49.                         end
  50.                     end
  51.                     room.atmosf = room.atmosf - 1
  52.                 end
  53.                 if room.podiv >= 0 then
  54.                     if xdist(small, lebka) <= 2 and look_at(small, lebka) and lebka.dir == dir_no then
  55.                         if room.podiv == 0 and small.cinnost == 0 then
  56.                             if no_dialog() then
  57.                                 addm(20, "k1-m-podivin")
  58.                                 addv(2, "k1-v-proc")
  59.                                 addm(2, "k1-m-lebku")
  60.                                 addv(2, "k1-v-jejeho")
  61.                                 if random(2) == 0 then
  62.                                     addm(5, "k1-m-mysli")
  63.                                 end
  64.                             else
  65.                                 room.podiv = room.podiv + 10
  66.                             end
  67.                         end
  68.                         room.podiv = room.podiv - 1
  69.                     end
  70.                 end
  71.                 if room.podekovat == 0 and small.Y <= 7 and small.X == 17 then
  72.                     room.podekovat = 1
  73.                     if no_dialog() then
  74.                         addm(5, "k1-m-diky")
  75.                         addv(3, "k1-v-radose")
  76.                     end
  77.                 end
  78.                 switch(room.chob){
  79.                     [1] = function()
  80.                         if small.X == chobot.X + 1 and small.Y == chobot.Y then
  81.                             if no_dialog() then
  82.                                 addv(0, "k1-v-opatrne")
  83.                                 addm(3, "k1-m-tospisona")
  84.                             end
  85.                             room.chob = 0
  86.                         end
  87.                     end,
  88.                     [2] = function()
  89.                         if look_at(small, chobot) and dist(small, chobot) == 2 then
  90.                             if no_dialog() then
  91.                                 addm(4, "k1-m-chobotnice")
  92.                                 addv(6, "k1-v-patrila")
  93.                                 planDialogSet(8, "k1-pap-drahousek", 101, papouch, "stav")
  94.                             end
  95.                             room.chob = 0
  96.                         end
  97.                     end,
  98.                 }
  99.                 if room.truh >= 0 then
  100.                     if dist(small, truhla) < 2 then
  101.                         if room.truh == 0 then
  102.                             if no_dialog() then
  103.                                 room.truh = room.truh - 1
  104.                                 switch(random(2)){
  105.                                     [0] = function()
  106.                                         addm(0, "k1-m-copak")
  107.                                         addv(3, "k1-v-kdovi")
  108.                                         planDialogSet(6, "k1-pap-drahokamy", 101, papouch, "stav")
  109.                                     end,
  110.                                     [1] = function()
  111.                                         addm(0, "k1-m-myslis")
  112.                                         addv(random(10), "k1-v-bedna")
  113.                                     end,
  114.                                 }
  115.                             else
  116.                                 room.truh = room.truh - 10
  117.                             end
  118.                         else
  119.                             room.truh = room.truh - 1
  120.                         end
  121.                     end
  122.                 end
  123.  
  124.                 if room.mov == 0 and random(100) < 1 then
  125.                     room.mov = 1
  126.                 end
  127.                 if room.mov == 1 and big:getTouchDir() ~= dir_no and room:getTouchDir() ~= dir_no then
  128.                     local touchDir = room:getTouchDir()
  129.                     local shiftX, shiftY = getDirShift(touchDir)
  130.                     screenShiftX = screenShiftX + shiftX * 15
  131.                     screenShiftY = screenShiftY + shiftY * 15
  132.                     game_setScreenShift(screenShiftX, screenShiftY)
  133.                     if no_dialog() then
  134.                         room.mov = 2
  135.                         addm(4, "k1-m-codelas")
  136.                         addv(3, "k1-v-promin")
  137.                     end
  138.                 end
  139.                 if room.mov == 1 or room.mov == 2 then
  140.                     screenShiftX = screenShiftX - screenShiftX / 10
  141.                     screenShiftY = screenShiftY - screenShiftY / 10
  142.                     game_setScreenShift(screenShiftX, screenShiftY)
  143.                 end
  144.             end
  145.         end
  146.     end
  147.  
  148.     -- -------------------------------------------------------------
  149.     local function prog_init_truhla()
  150.         return function()
  151.             if truhla.dir ~= dir_no and level_isNewRound() then
  152.                 truhla:talk("k1-x-vrz", VOLUME_FULL)
  153.             end
  154.         end
  155.     end
  156.  
  157.     -- -------------------------------------------------------------
  158.     local function prog_init_papouch()
  159.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  160.  
  161.         papouch.stav = 0
  162.         papouch.strcil = 0
  163.         papouch.smalse = 0
  164.         papouch.nekoukej = 0
  165.         papouch.tlustej = 0
  166.  
  167.         return function()
  168.             switch(papouch.stav){
  169.                 [0] = function()
  170.                     if no_dialog() then
  171.                         if (papouch.dir == dir_left or papouch.dir == dir_right) and papouch.strcil == 0 and random(6) == 0 then
  172.                             papouch.strcil = 1
  173.                             planDialogSet(0, "k1-pap-nestrkej", 101, papouch, "stav")
  174.                         elseif papouch.Y == 18 and papouch.smalse == 0 then
  175.                             papouch.smalse = 1
  176.                             planDialogSet(0, "k1-pap-prekazet", 101, papouch, "stav")
  177.                         elseif poklop.Y == 7 and small.Y > 7 and small.Y < 17 and small.X > 7 and big.Y < 7 and papouch.smalse == 0 then
  178.                             papouch.smalse = 1
  179.                             planDialogSet(0, "k1-pap-prcice", 101, papouch, "stav")
  180.                         elseif papouch.nekoukej == 0 and dist(small, papouch) <= 1 and random(100) < 5 then
  181.                             papouch.nekoukej = 1
  182.                             planDialogSet(0, "k1-pap-vodprejskni", 102, papouch, "stav")
  183.                         elseif papouch.nekoukej == 0 and dist(big, papouch) <= 1 and random(100) < 5 then
  184.                             papouch.nekoukej = 2
  185.                             planDialogSet(0, "k1-pap-vodprejskni", 102, papouch, "stav")
  186.                         elseif papouch.nekoukej == 1 and dist(small, papouch) > 2 and random(100) < 25 then
  187.                             planDialogSet(0, "k1-pap-noproto", 101, papouch, "stav")
  188.                         elseif papouch.nekoukej == 2 and dist(big, papouch) > 2 and random(100) < 25 then
  189.                             planDialogSet(0, "k1-pap-noproto", 101, papouch, "stav")
  190.                         elseif papouch.tlustej == 0 and trubka.X >= 13 and trubka.Y == 18 then
  191.                             papouch.tlustej = 1
  192.                             planDialogSet(0, "k1-pap-sestlustej", 101, papouch, "stav")
  193.                             papouch.stav = 1
  194.                         elseif random(250) == 0 then
  195.                             switch(random(7)){
  196.                                 [0] = function()
  197.                                     planDialogSet(0, "k1-pap-sucharek", 101, papouch, "stav")
  198.                                 end,
  199.                                 [1] = function()
  200.                                     planDialogSet(0, "k1-pap-kruty", 101, papouch, "stav")
  201.                                 end,
  202.                                 [2] = function()
  203.                                     planDialogSet(0, "k1-pap-3xkruty", 101, papouch, "stav")
  204.                                 end,
  205.                                 [3] = function()
  206.                                     planDialogSet(0, "k1-pap-kruci", 101, papouch, "stav")
  207.                                 end,
  208.                                 [4] = function()
  209.                                     planDialogSet(0, "k1-pap-sakris", 101, papouch, "stav")
  210.                                 end,
  211.                                 [5] = function()
  212.                                     planDialogSet(0, "k1-pap-trhnisi", 101, papouch, "stav")
  213.                                 end,
  214.                                 [6] = function()
  215.                                     planDialogSet(0, "k1-pap-problem", 101, papouch, "stav")
  216.                                 end,
  217.                             }
  218.                             papouch.stav = 1
  219.                         end
  220.                     end
  221.                 end,
  222.                 [101] = function()
  223.                     if papouch.nekoukej > 0 then
  224.                         papouch.nekoukej = 3
  225.                     end
  226.                     papouch.afaze = random(2)
  227.                 end,
  228.                 [102] = function()
  229.                     papouch.afaze = random(2)
  230.                 end,
  231.             }
  232.             papouch:updateAnim()
  233.         end
  234.     end
  235.  
  236.     -- -------------------------------------------------------------
  237.     local function prog_init_chobot()
  238.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  239.  
  240.         chobot.lastdir = dir_no
  241.         chobot.oci = 0
  242.         chobot.chapadla = 0
  243.         chobot.akcnost = 2
  244.  
  245.         return function()
  246.             if chobot.dir ~= dir_no then
  247.                 chobot.akcnost = 7
  248.             elseif chobot.akcnost > 2 and math.mod(game_getCycles(), 5) == 0 then
  249.                 chobot.akcnost = chobot.akcnost - 1
  250.             end
  251.             if chobot.dir ~= chobot.lastdir then
  252.                 if not chobot:isTalking() then
  253.                     if chobot.dir == dir_down then
  254.                         chobot:talk("k1-chob-p", VOLUME_FULL)
  255.                     elseif chobot.dir ~= dir_no then
  256.                         switch(random(3)){
  257.                             [0] = function()
  258.                                 chobot:talk("k1-chob-1", VOLUME_FULL)
  259.                             end,
  260.                             [1] = function()
  261.                                 chobot:talk("k1-chob-2", VOLUME_FULL)
  262.                             end,
  263.                             [2] = function()
  264.                                 chobot:talk("k1-chob-3", VOLUME_FULL)
  265.                             end,
  266.                         }
  267.                     end
  268.                 end
  269.                 chobot.lastdir = chobot.dir
  270.             end
  271.             if chobot.dir == dir_no and math.mod(game_getCycles(), chobot.akcnost) == 0 then
  272.                 if random(2) == 0 then
  273.                     if chobot.chapadla < 2 then
  274.                         chobot.chapadla = chobot.chapadla + 1
  275.                     else
  276.                         chobot.chapadla = 0
  277.                     end
  278.                 else
  279.                     if chobot.chapadla > 0 then
  280.                         chobot.chapadla = chobot.chapadla - 1
  281.                     else
  282.                         chobot.chapadla = 2
  283.                     end
  284.                 end
  285.             end
  286.             pomb1 = xdist(small, chobot) == 0 and ydist(small, chobot) <= 0 or xdist(big, chobot) == 0 and ydist(big, chobot) <= 0
  287.             pomb1 = pomb1 or chobot.dir ~= dir_no
  288.             if pomb1 then
  289.                 chobot.oci = 1
  290.             end
  291.             switch(chobot.oci){
  292.                 [0] = function()
  293.                     if random(100) < 10 then
  294.                         chobot.oci = 2
  295.                     end
  296.                 end,
  297.                 [2] = function()
  298.                     if random(100) < 10 then
  299.                         chobot.oci = 0
  300.                     end
  301.                 end,
  302.                 [1] = function()
  303.                     if not pomb1 and random(100) < 20 then
  304.                         chobot.oci = 0
  305.                     end
  306.                 end,
  307.             }
  308.             chobot.afaze = chobot.oci + 3 * chobot.chapadla
  309.             chobot:updateAnim()
  310.         end
  311.     end
  312.  
  313.     -- -------------------------------------------------------------
  314.     local function prog_init_small()
  315.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  316.  
  317.         small.leb = 0
  318.         small.cinnost = 0
  319.         small.delay = 0
  320.  
  321.         return function()
  322.             if no_dialog() then
  323.                 switch(small.cinnost){
  324.                     [0] = function()
  325.                         if lebka.dir ~= dir_no and lebka.dir ~= dir_down and small.dir ~= dir_no and (small.leb == 0 or random(100) < 10) and level_isNewRound() then
  326.                             small.leb = 1
  327.                             small:talk("k1-m-fuj")
  328.                         end
  329.                     end,
  330.                 }
  331.             end
  332.         end
  333.     end
  334.  
  335.     -- -------------------------------------------------------------
  336.     local function prog_init_big()
  337.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  338.  
  339.         big.cinnost = 0
  340.  
  341.     end
  342.  
  343.     -- --------------------
  344.     local update_table = {}
  345.     local subinit
  346.     subinit = prog_init_room()
  347.     if subinit then
  348.         table.insert(update_table, subinit)
  349.     end
  350.     subinit = prog_init_truhla()
  351.     if subinit then
  352.         table.insert(update_table, subinit)
  353.     end
  354.     subinit = prog_init_papouch()
  355.     if subinit then
  356.         table.insert(update_table, subinit)
  357.     end
  358.     subinit = prog_init_chobot()
  359.     if subinit then
  360.         table.insert(update_table, subinit)
  361.     end
  362.     subinit = prog_init_small()
  363.     if subinit then
  364.         table.insert(update_table, subinit)
  365.     end
  366.     subinit = prog_init_big()
  367.     if subinit then
  368.         table.insert(update_table, subinit)
  369.     end
  370.     return update_table
  371. end
  372. local update_table = prog_init()
  373.  
  374.  
  375. -- -----------------------------------------------------------------
  376. -- Update
  377. -- -----------------------------------------------------------------
  378. function prog_update()
  379.     for key, subupdate in pairs(update_table) do
  380.         subupdate()
  381.     end
  382. end
  383.  
  384.